package com.shunan.miaosha.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.shunan.miaosha.beans.MiaoshaGoods;
import com.shunan.miaosha.vo.GoodsVo;

@Mapper
public interface GoodsDao {
	
	@Select("SELECT  g.goods_name goodsName,  g.goods_img goodsImg,  g.goods_detail goodsDetail, g.goods_price goodsPrice,  g.goods_stock goodsStock,  g.goods_title goodsTitle, g.id id, mg.stock_count stockCount,  mg.start_date startDate,  mg.end_date endDate, mg.miaosha_price miaoshaPrice FROM  miaosha_goods mg LEFT JOIN goods g  ON mg.goods_id = g.id ")
	public List<GoodsVo> listGoodsVo();

	@Select("select g.goods_name goodsName,  g.goods_img goodsImg,  g.goods_detail goodsDetail, g.goods_price goodsPrice,  g.goods_stock goodsStock,  g.goods_title goodsTitle, g.id id,mg.stock_count stockCount,  mg.start_date startDate,  mg.end_date endDate, mg.miaosha_price miaoshaPrice from miaosha_goods mg left join goods g on mg.goods_id = g.id where g.id = #{goodsId}")
	public GoodsVo getGoodsVoByGoodsId(@Param("goodsId")int goodsId);

	@Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{goodsId} and stock_count>=1")
	public int reduceStock(MiaoshaGoods g);
	
}
